﻿using System;
using System.Threading;

public class Clock
{
    public event EventHandler Tick;
    public event EventHandler Alarm;

    // 触发Tick事件 
    protected virtual void OnTick() => Tick?.Invoke(this, EventArgs.Empty);

    // 触发Alarm事件 
    protected virtual void OnAlarm() => Alarm?.Invoke(this, EventArgs.Empty);

    public void Start(int alarmAfterSeconds)
    {
        for (int i = 0; i < alarmAfterSeconds; i++)
        {
            OnTick();           // 每秒触发嘀嗒 
            Thread.Sleep(1000); // 模拟1秒间隔 
        }
        OnAlarm();             
    }
}

class Program
{
    static void Main()
    {
        var clock = new Clock();

        // 订阅事件 
        clock.Tick += (s, e) => Console.WriteLine("滴答...");
        clock.Alarm += (s, e) => Console.WriteLine(">>> 叮铃铃！该起床了！ <<<");

        Console.WriteLine("闹钟启动（5秒后响铃）");
        clock.Start(5);

        Console.ReadKey();
    }
}